﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using System.Data.OracleClient;
namespace GSLMS.DAL.Oracle
{
	/// <summary>
	/// 数据访问类:FIN_EXCLOANSET
	/// </summary>
	public partial class FIN_EXCLOANSET : BaseDAL<GSLMS.Entity.TB_FIN_EXCLOANSET>
	{
		private readonly GSLMS.Core.Loger log = new Core.Loger();
		public FIN_EXCLOANSET()
		{}
		#region  Method
		/// <summary>
		///  增加一条数据
		/// </summary>
		public override bool Add(GSLMS.Entity.TB_FIN_EXCLOANSET model)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", model.ID),
								new OracleParameter("P_CUSTNAME", model.CUSTNAME),
								new OracleParameter("P_CUSTNO", model.CUSTNO),
								new OracleParameter("P_MOBILE1", model.MOBILE1),
								new OracleParameter("P_MOBILE2", model.MOBILE2),
								new OracleParameter("P_LINKMAN", model.LINKMAN),
								new OracleParameter("P_LINKMANMOBILE", model.LINKMANMOBILE),
								new OracleParameter("P_LINKMANTELCODE", model.LINKMANTELCODE),
								new OracleParameter("P_LINKMANTEL", model.LINKMANTEL),
								new OracleParameter("P_LINKMANTELSUB", model.LINKMANTELSUB),
								new OracleParameter("P_PAYMENT", model.PAYMENT),
								new OracleParameter("P_ISEFFECT", model.ISEFFECT),
								new OracleParameter("P_CREATEBY", model.CREATEBY),
								new OracleParameter("P_CREATEDATE", model.CREATEDATE),
								new OracleParameter("P_REMARK", model.REMARK),
								new OracleParameter("P_SPAREFIELD1", model.SPAREFIELD1),
								new OracleParameter("P_SPAREFIELD2", model.SPAREFIELD2),
								new OracleParameter("P_SPAREFIELD3", model.SPAREFIELD3)};
  
			for (int i = 0; i < 18; i++)
			{
				parms[i].Direction = ParameterDirection.Input;
			}

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_fin_excloanset_add", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///  更新一条数据
		/// </summary>
		public override bool Update(GSLMS.Entity.TB_FIN_EXCLOANSET model)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", model.ID),
								new OracleParameter("P_CUSTNAME", model.CUSTNAME),
								new OracleParameter("P_CUSTNO", model.CUSTNO),
								new OracleParameter("P_MOBILE1", model.MOBILE1),
								new OracleParameter("P_MOBILE2", model.MOBILE2),
								new OracleParameter("P_LINKMAN", model.LINKMAN),
								new OracleParameter("P_LINKMANMOBILE", model.LINKMANMOBILE),
								new OracleParameter("P_LINKMANTELCODE", model.LINKMANTELCODE),
								new OracleParameter("P_LINKMANTEL", model.LINKMANTEL),
								new OracleParameter("P_LINKMANTELSUB", model.LINKMANTELSUB),
								new OracleParameter("P_PAYMENT", model.PAYMENT),
								new OracleParameter("P_ISEFFECT", model.ISEFFECT),
								new OracleParameter("P_CREATEBY", model.CREATEBY),
								new OracleParameter("P_CREATEDATE", model.CREATEDATE),
								new OracleParameter("P_REMARK", model.REMARK),
								new OracleParameter("P_SPAREFIELD1", model.SPAREFIELD1),
								new OracleParameter("P_SPAREFIELD2", model.SPAREFIELD2),
								new OracleParameter("P_SPAREFIELD3", model.SPAREFIELD3)};
  
			for (int i = 0; i < 18; i++)
			{
				parms[i].Direction = ParameterDirection.Input;
			}

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_fin_excloanset_update", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///  删除一条数据
		/// </summary>
		public override bool Delete(long ID)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", ID)};
  
				parms[0].Direction = ParameterDirection.Input;

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_fin_excloanset_delete", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///DataRowToModel 
		/// </summary>
		private GSLMS.Entity.TB_FIN_EXCLOANSET DataRowToModel(DataRow dr)
		{
			if (dr != null && dr.ItemArray.Length > 0)
			{
				GSLMS.Entity.TB_FIN_EXCLOANSET model = new GSLMS.Entity.TB_FIN_EXCLOANSET();
				if(dr["ID"]!=null && dr["ID"].ToString()!="")
				{
					model.ID=OracleHelper.ToLong(dr["ID"].ToString());
				}
				if(dr["CUSTNAME"]!=null && dr["CUSTNAME"].ToString()!="")
				{
					model.CUSTNAME=dr["CUSTNAME"].ToString();
				}
				if(dr["CUSTNO"]!=null && dr["CUSTNO"].ToString()!="")
				{
					model.CUSTNO=dr["CUSTNO"].ToString();
				}
				if(dr["MOBILE1"]!=null && dr["MOBILE1"].ToString()!="")
				{
					model.MOBILE1=dr["MOBILE1"].ToString();
				}
				if(dr["MOBILE2"]!=null && dr["MOBILE2"].ToString()!="")
				{
					model.MOBILE2=dr["MOBILE2"].ToString();
				}
				if(dr["LINKMAN"]!=null && dr["LINKMAN"].ToString()!="")
				{
					model.LINKMAN=dr["LINKMAN"].ToString();
				}
				if(dr["LINKMANMOBILE"]!=null && dr["LINKMANMOBILE"].ToString()!="")
				{
					model.LINKMANMOBILE=dr["LINKMANMOBILE"].ToString();
				}
				if(dr["LINKMANTELCODE"]!=null && dr["LINKMANTELCODE"].ToString()!="")
				{
					model.LINKMANTELCODE=dr["LINKMANTELCODE"].ToString();
				}
				if(dr["LINKMANTEL"]!=null && dr["LINKMANTEL"].ToString()!="")
				{
					model.LINKMANTEL=dr["LINKMANTEL"].ToString();
				}
				if(dr["LINKMANTELSUB"]!=null && dr["LINKMANTELSUB"].ToString()!="")
				{
					model.LINKMANTELSUB=dr["LINKMANTELSUB"].ToString();
				}
				if(dr["PAYMENT"]!=null && dr["PAYMENT"].ToString()!="")
				{
                    model.PAYMENT = OracleHelper.ToInt(dr["PAYMENT"].ToString());
				}
				if(dr["ISEFFECT"]!=null && dr["ISEFFECT"].ToString()!="")
				{
                    model.ISEFFECT = OracleHelper.ToInt(dr["ISEFFECT"].ToString());
				}
				if(dr["CREATEBY"]!=null && dr["CREATEBY"].ToString()!="")
				{
					model.CREATEBY=dr["CREATEBY"].ToString();
				}
				if(dr["CREATEDATE"]!=null && dr["CREATEDATE"].ToString()!="")
				{
					model.CREATEDATE=DateTime.Parse(dr["CREATEDATE"].ToString());
				}
				if(dr["REMARK"]!=null && dr["REMARK"].ToString()!="")
				{
					model.REMARK=dr["REMARK"].ToString();
				}
				if(dr["SPAREFIELD1"]!=null && dr["SPAREFIELD1"].ToString()!="")
				{
                    model.SPAREFIELD1 = OracleHelper.ToInt(dr["SPAREFIELD1"].ToString());
				}
				if(dr["SPAREFIELD2"]!=null && dr["SPAREFIELD2"].ToString()!="")
				{
					model.SPAREFIELD2=dr["SPAREFIELD2"].ToString();
				}
				if(dr["SPAREFIELD3"]!=null && dr["SPAREFIELD3"].ToString()!="")
				{
					model.SPAREFIELD3=dr["SPAREFIELD3"].ToString();
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public override GSLMS.Entity.TB_FIN_EXCLOANSET GetByID(long ID)
		{
			GSLMS.Entity.TB_FIN_EXCLOANSET sModel = new GSLMS.Entity.TB_FIN_EXCLOANSET();
			string sql = "";
			sql = "select * from TB_FIN_EXCLOANSET where id=" + ID.ToString();
			DataSet ds = OracleHelper.ExecuteDataset(sql);
			if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
			{
				sModel = DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
			return null;
			}
			return sModel;
		}

		/// <summary>
		/// 分页提取数据
		/// </summary>
		public override List<GSLMS.Entity.TB_FIN_EXCLOANSET> GetList(GSLMS.Entity.TB_FIN_EXCLOANSET searchParam)
		{
			var list=new List<GSLMS.Entity.TB_FIN_EXCLOANSET>();
			DataTable dt = null;
			string tblName = "TB_FIN_EXCLOANSET";
			string sqlWhere="";
			string strSort="";
			int pageSize=20;
			int pageIndex=1;
			string strFields="*";
			int totalCount = 0;
			int countFlag = 1;
			dt = OracleHelper.GetPageData(tblName, strFields, strSort, pageSize, pageIndex,countFlag, sqlWhere, out totalCount);
			if (dt != null && dt.Rows.Count > 0)
			{
				for (int i = 0; i < dt.Rows.Count; i++)
				{
					GSLMS.Entity.TB_FIN_EXCLOANSET model = new GSLMS.Entity.TB_FIN_EXCLOANSET();
					model = DataRowToModel(dt.Rows[i]);
					list.Add(model);
				}
			}
			else
			{
				return null;
			}
			return list;
		}

		#endregion  Method
	}
}

